package com.aqiang.day0420;

import android.media.MediaPlayer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.VideoView;

import com.aqiang.core.view.BaseActivity;
import com.hyphenate.EMCallBack;
import com.hyphenate.chat.EMClient;
import com.hyphenate.chat.EMMessage;

public class MainActivity extends BaseActivity {
    private VideoView mVideoMain;
    private Button mBtMianSend;
    @Override
    protected void initEvent() {
        mVideoMain.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mp) {
                mVideoMain.start();
            }
        });

        mBtMianSend.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//创建一条文本消息，content为消息文字内容，toChatUsername为对方用户或者群聊的id，后文皆是如此
                EMMessage message = EMMessage.createTxtSendMessage("你好", "1002");
//如果是群聊，设置chattype，默认是单聊

//发送消息
                EMClient.getInstance().chatManager().sendMessage(message);
            }
        });
    }

    @Override
    protected void initData() {
        EMClient.getInstance().login("1001","123456",new EMCallBack() {//回调
            @Override
            public void onSuccess() {
                EMClient.getInstance().groupManager().loadAllGroups();
                EMClient.getInstance().chatManager().loadAllConversations();
                Log.d("main", "登录聊天服务器成功！");
            }

            @Override
            public void onProgress(int progress, String status) {

            }

            @Override
            public void onError(int code, String message) {
                Log.d("main", "登录聊天服务器失败！");
            }
        });
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        mBtMianSend = (Button) findViewById(R.id.bt_mian_send);
        mVideoMain = (VideoView) findViewById(R.id.video_main);
        //播放
        mVideoMain.setVideoPath("http://ivi.bupt.edu.cn/hls/cctv1hd.m3u8");
    }

    @Override
    protected int bindLayout() {
        return R.layout.activity_main;
    }
}
